package com.mobiusws.reports.action;

import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.util.ServletContextAware;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.mobiusws.reports.dao.DailyFraudSummaryDao;
import com.mobiusws.reports.dao.InitOperatorDao;
import com.mobiusws.reports.dao.TestDao;
import com.mobiusws.reports.model.DailyFraudSummary;
import com.mobiusws.reports.model.LoginInfo;
import com.mobiusws.util.ExportUtil;
import com.mobiusws.util.JsonUtil;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport  {

	private static final long serialVersionUID = 5395964004991248282L;

	@Resource
	private DailyFraudSummaryDao gridTestDao;
	@Resource
	private JsonUtil jsonUtil;
	@Resource
	private InitOperatorDao initOperatorDao;

	private String errorMessage;

	private String username;
	private String password;
	private String selDate;
	private int start;
	private int limit;
	private int total;
	
	public String getErrorMessage() {
		return errorMessage;
	}

	public void setErrorMessage(String errorMessage) {
		this.errorMessage = errorMessage;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getSelDate() {
		return selDate;
	}

	public void setSelDate(String selDate) {
		this.selDate = selDate;
	}

	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}

	// a getter is required to get the result in pages
//	public String getResult() {
//		return result;
//	}
//
//	public void setResult(String result) {
//		this.result = result;
//	}

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}
	
	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

	@Override
	public String execute() throws Exception {
		String result="";
		//System.out.printf("%s, %s\n", username, password);
		ActionContext actionContext = ActionContext.getContext();
	    Map session = actionContext.getSession();
		if(("mws".equals(username) && "mws123".equals(password))) {
			result=SUCCESS;
			initOperatorDao.init();
			session.put("username", username);
		} else {
			result=INPUT;
			errorMessage="Bad credentials";
			session.put("username", null);
		}
		
		return result;
	}

}
